flattenlistmodel: Give access to child models
authorMatthias Clasen <mclasen@redhat.com>
Sun, 22 Mar 2020 17:19:55 +0000 (13:19 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 25 Mar 2020 22:47:46 +0000 (18:47 -0400)
Add an api to retrieve the model containing a given
item in a flatten listmodel. This is useful when the
individual items in the list don't have backpointers.

docs/reference/gtk/gtk4-sections.txt
gtk/gtkflattenlistmodel.c
gtk/gtkflattenlistmodel.h

index 13b3f831f6a9069c4c400921fa28911ca443d904..1f243f279705460e8f278f4d00b153ee0d99c67f 100644 (file)
@@ -1316,6 +1316,7 @@ GtkFlattenListModel
 gtk_flatten_list_model_new
 gtk_flatten_list_model_set_model
 gtk_flatten_list_model_get_model
+gtk_flatten_list_model_get_model_for_item
 <SUBSECTION Standard>
 GTK_FLATTEN_LIST_MODEL
 GTK_IS_FLATTEN_LIST_MODEL
index 3204f5b5eae8710b50a56dadb35eba268ab85c32..f557cb2232939dc82335117b77ee83779666c6e5 100644 (file)
@@ -539,3 +539,28 @@ gtk_flatten_list_model_get_model (GtkFlattenListModel *self)
 
   return self->model;
 }
+
+/**
+ * gtk_flatten_list_model_get_model_for_item:
+ * @self: a #GtkFlattenListModel
+ * @position: a position
+ *
+ * Returns the model containing the item at the given position.
+ *
+ * Returns: (transfer none): the model containing the item at @position
+ */
+GListModel *
+gtk_flatten_list_model_get_model_for_item (GtkFlattenListModel *self,
+                                           guint                position)
+{
+  FlattenNode *node;
+
+  if (!self->items)
+    return NULL;
+
+  node = gtk_flatten_list_model_get_nth (self->items, position, NULL);
+  if (node == NULL)
+    return NULL;
+
+  return node->model;
+}
index 75e39404d74d68aa100bc1f62feac437851c84bd..ec1eaaa84ec7789110fcbb57746c72d00dacda22 100644 (file)
@@ -45,6 +45,10 @@ void                    gtk_flatten_list_model_set_model        (GtkFlattenListM
 GDK_AVAILABLE_IN_ALL
 GListModel *            gtk_flatten_list_model_get_model        (GtkFlattenListModel    *self);
 
+GDK_AVAILABLE_IN_ALL
+GListModel *            gtk_flatten_list_model_get_model_for_item (GtkFlattenListModel    *self,
+                                                                   guint                   position);
+
 G_END_DECLS
 
 #endif /* __GTK_FLATTEN_LIST_MODEL_H__ */